-
Notifications
You must be signed in to change notification settings - Fork 128
Add warning/error handling for --include-external #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
465d439
to
b29f86f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts...
List<Source> matchedSources = context.librarySources | ||
.where((library) => matchesLibrary(includeExternal, library)); | ||
if (matchedSources.isEmpty) { | ||
print(" warning: $quotedArgString -- " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: +
not needed here. adjacent String literals auto-concat. Is nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
for (String includeExternal in includeExternals) { | ||
var quotedArgString = "'--include-external $includeExternal'"; | ||
List<Source> matchedSources = context.librarySources | ||
.where((library) => matchesLibrary(includeExternal, library)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add .toList()
here – make sure we don't re-iterate the iterable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would it mean to re-iterate the iterable? Is this a general pattern we should have the analyzer warn about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. I should write-up a little dartpad thing to show this.
This makes --include-external a bit harder to use incorrectly (with surprising results).
Cases I would like to test (but don't see an easy way how would include):
--external-library asldkfjsdf
hit the "warn no libraries found" case--external-library dart
hit the "multiple libraries found" case--external-library dartdoc.dart
hit the "library already found" caseI looked at adding tests to test/dartdoc_test.dart, but those do not seem set up to handle logging. I looked briefly ad breaking this logic out into its own function, but it wasn't clear how to provide the necessary AnalysisContext with sources.
I've been able to trigger the first two test cases manually, but not yet seen the 3rd.